const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const app = getApp();
Page({
    data: {
        userInfo: {
            nickName: '点击登录',
            // avatarUrl: '/assets/my.png',
            mobile:''
        },
        phone:'',
        isMember: wx.getStorageSync('userInfo').isMember,
        hasLogin: false,
        openid: null,
        title: '会员请完善个人信息后，才能进行会费缴纳'
    },
    onLoad(){
       const that =this
        // 赋值isMember(0不显示,1显示)
        that.setData({
            isMember:wx.getStorageSync('userInfo').isMember
        })

    },
    onShareAppMessage() {
        return {};
    },

    onShow() {
        //获取用户的登录信息
        if (app.globalData.hasLogin) {
            // let userInfo = wx.getStorageSync('userInfo');
            let userId = wx.getStorageSync('userId')
            util.request(api.userInfoDetail, {id: userId}, 'get').then(res => {
                if (res.errno === 200) {
                  console.log(res)
                  if (res.data.mobile != "") {
                    console.log(res,'res11')
                    let userInfo = {
                        nickName: res.data.nickName,
                        // avatarUrl: '/assets/my.png',
                        mobile:res.data.mobile
                    }
                    this.setData({
                        userInfo
                    })
                  }else{
                    console.log(res,'res22')
                         this.setData({
                    userInfo,
                    hasLogin: false
                });
                  } 
                    
                } else {
                  this.setData({
                    // userInfo: userInfo,
                    hasLogin: true
                });
                    // console.log(res.errmsg)
                }
            }).catch(e => {
            })
            this.setData({
                // userInfo: userInfo,
                hasLogin: true
            });
        } else {
            this.goLogin()
        }
        //赋值isMember(0不显示,1显示)
        this.setData({
          phone: wx.getStorageSync('userInfo').phone,
            isMember: wx.getStorageSync('userInfo').isMember
        })

    },
    goLogin() {
        if (!this.data.hasLogin) {
            wx.navigateTo({
                url: "/pages/Login/Login"
            });
        }
    },
    exit() {
        wx.showModal({
            title: '',
            confirmColor: '#b4282d',
            content: '退出登录？',
            success: function (res) {
                if (!res.confirm) {
                    return;
                }
                util.request(api.AuthLogout, {}, 'POST');
                app.globalData.hasLogin = false;
                wx.removeStorageSync('token');
                wx.removeStorageSync('userInfo');
                wx.reLaunch({
                    url: '/pages/Home/Home'
                });
            }
        })
    },
    subscribe_tap() {
        wx.navigateTo({url: '/pages/Subscribe/Subscribe'});
    },
    view_13OnClick() {
        if (wx.getStorageSync('userInfo').isMember === 1 ||wx.getStorageSync('userInfo').isMember === "1") {
            wx.navigateTo({url: '/pages/PayAdd/PayAdd'});
        } else {
            wx.showModal({
                title: '提示',
                content: '您当前不是会员，无法缴费，请重新登录后完善个人信息。如需入会请联系021-62581170！',
                showCancel: false,
                confirmText: '确定'
            });
        }
    },
    view_22OnClick() {
        wx.navigateTo({url: '/pages/PayRecord/PayRecord'});
    },
    view_23OnClick() {
        wx.navigateTo({url: '/pages/ActivityNotice/ActivityNotice'});
    },
    view_24OnClick() {
        wx.navigateTo({url: '/pages/ReceiptInfo/ReceiptInfo'});
    },
    view_25OnClick() {
        wx.navigateTo({url: '/pages/RemittanceList/RemittanceList'});
    },
    view_26OnClick() {
        wx.navigateTo({url: '/pages/SignIn/SignIn'});
    },
    image_1OnClick() {
        wx.navigateTo({url: '/pages/Home/Home'});
    },
    image_2OnClick() {
        wx.navigateTo({url: '/pages/index'});
    },
    handleEdit() {
        wx.navigateTo({
            url: `/pages/MyInfo/MyInfo?title=${this.data.title}&id=${ wx.getStorageSync('userId')} `,
        })
    }
});
